import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        TopMenu: [],
        Active: '',
        width: '100%'
    },
    mutations: {
        TopMenuData(state, data) {
            let menu = []
            for (var i in data) {
                if (data[i].menu) menu.push({
                    title: data[i].title || '',
                    name: data[i].name || '',
                    icon: data[i].icon || '',
                    width: data[i].width || '',
                    children: data[i].children || []
                })
            }
            state.TopMenu = menu
        },
        UpActive(state, data) {
            state.Active = data.name
            for (var i in state.TopMenu) {
                if (state.TopMenu[i].name == state.Active) {
                    state.width = state.TopMenu[i].width
                    break
                }
            }
        }
    },
    actions: {}
})
